<?php

/**
 * XHTML_TBody, xhtml_lib
 * 
 * This file contains the source code for the XHTML_TBody class.
 * @author Fernando Jimenez Mocobono <fjmcool@gmail.com>
 * @version 0.1
 * @package xhtml_lib
 */

include_once "XHTML_Table_Common_Element.php";
include_once "XHTML__Table_Content.php";
include_once "XHTML_Tr.php";

/**
 * The XHTML_TBody class is a handler for the tbody xhtml-strict tag as a part 
 * of a xhtml-strict php-handler implementation.
 */
class XHTML_TBody extends XHTML_Table_Common_Element 
	implements XHTML__Table_Content {
    
    // inner elements
    
    /**
     * Inner array of XHTML_Tr.
     * 
     * @var array
     */
    protected $rows;
    
    
    // Methods
    
    /**
     * Constructs a XHTML_TBody object.
     */
    function __construct()
    {
    	parent::__construct();
    }
    
    
    /**
     * Sets the XHTML_Tr elements array.
     *
     * @param array $rows
     */
    function setRows($rows) {
        $this->rows;
    }
    
    /**
     * Gets the XHTML_Tr elements array.
     *
     * @return array
     */
    function getRows()
    {
        return $this->rows;
    }
    
    /**
     * Adds a XHTML_Tr element to the inner array of this object.
     * 
     * @param XHTML_Tr $row
     */
    function addRow(XHTML_Tr $row)
    {
        array_push($this->rows, $row);
    }
    
    /**
     * Removes a XHTML_Tr element from the inner array of this object.
     * 
     * @param XHTML_Tr $row
     */
    function removeRow(XHTML_Tr $row)
	{
        if (($res = array_search($row, $this->rows)) !== false) {
            unset($this->rows[$res]);
        }
    }
 
    // Overriding the toString method for a proper implementation.
    
    /**
    * Returns the string representation for echoing the class atributes.
    *
    * @return string
    */
    function toString()
    {
    	$auxString = "<tbody".parent::toString();
    	
    	$auxString = $auxString.">/n";
    	
        if (count($this->rows) > 0) {
            foreach ($this->rows as $row) {
                $auxString = $auxString.$row->toString();
            }
        }
    	
    	$auxString = $auxString."</tbody>\n";
                
        return $auxString;
    }
    
}